package com.zqp.wiremock;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.configureFor;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.removeAllMappings;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;

import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.core.io.ClassPathResource;

/**
 * @author zqp
 * @date 2017年12月20日
 * @description
 */
public class MockServer {

	public static void main(String[] args) throws IOException {
		
		configureFor(8081);
		removeAllMappings();
		mock("/order/1","01");	
	}

	private static void mock(String string, String fileName) throws IOException {
		ClassPathResource resource = new ClassPathResource("/mock/response/"+fileName+".txt");
		String content =StringUtils.join(FileUtils.readLines(resource.getFile(), "utf-8"),"\n") ;
		stubFor(get(urlEqualTo(string)).willReturn(aResponse().withBody(content).withStatus(200)));
	}
}
